﻿package framework.core;
import java.sql.*;
import java.io.*;
public abstract class DBData 
{
	public abstract void initObject(java.sql.ResultSet rs) throws Exception;
	
	public boolean isNullField(ResultSet rs,String fName) throws Exception
	{
		String val = rs.getString(fName);
		return val==null;
	}	
	public int getInt(java.sql.ResultSet rs,String fName) throws Exception
	{
		if(isNullField(rs,fName))
		{
			return Value.NULL_INT;
		}
		return rs.getInt(fName);
	}
	public double getDouble(ResultSet rs,String fName) throws Exception
	{
		if(isNullField(rs,fName))
		{
			return Value.NULL_DOUBLE;
		}
		return rs.getDouble(fName);
	}
	public String getString(ResultSet rs,String fName) throws Exception
	{
		if(isNullField(rs,fName))
		{
			return "";
		}
		return rs.getString(fName);
	}	
	public byte[] getBytes(ResultSet rs,String fName) throws Exception
	{
		InputStream stream = rs.getBinaryStream(fName);
	
		byte[] data = new byte[1024*1024*10];
		int offset = 0 ;
		for(;;)
		{
			int i = stream.read(data,offset,512);
			if(i==-1) break;
			offset += i ;
		}
		byte[] r = new byte[offset];
	
		for(int i=0;i<offset;i++)
		{
			r[i] = data[i];
		}
		return r;
	}
}